unit RaSqliteDsgn;

interface

uses
  DesignIntf, DesignEditors, FileCtrl,
  Classes, Controls, RaSqlite;

type

  TRaSQLiteEditor = Class( TComponentEditor )
    Function GetVerbCount: integer; Override;
    Function GetVerb( Index: integer ): String; Override;
    Procedure ExecuteVerb( Index: integer ); Override;
  End;

  TDatabasePropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteDatabaseProperty = class(TDatabasePropertyEditor)
  end;

  TTablePropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteTableNameProperty = class(TTablePropertyEditor)
  end;

  TMasterDetailPropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteMasterDetailProperty = class(TMasterDetailPropertyEditor)
  end;

  TStoragePropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteStorageProperty = class(TStoragePropertyEditor)
  end;

  TSyncPropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteSyncProperty = class(TSyncPropertyEditor)
  end;

  TDirPropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteDirProperty = class(TDirPropertyEditor)
  end;

  TDLLDirPropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteDLLDirProperty = class(TDLLDirPropertyEditor)
  end;

  TFileTypePropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteFileTypeProperty = class(TFileTypePropertyEditor)
  end;

  TTransactionPropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteTransactionProperty = class(TTransactionPropertyEditor)
  end;

  TCharEncPropertyEditor = class(TPropertyEditor)
  public
    function GetAttributes      : TPropertyAttributes; override;
    function GetValue           : string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
  end;

  TRaSQLiteCharEncProperty = class(TCharEncPropertyEditor)
  end;

implementation

uses
  RaGSQLite, SysUtils, Forms, Dialogs;

Function TRaSQLiteEditor.GetVerbCount: integer;
Begin
     Result := 1;
End;

Function TRaSQLiteEditor.GetVerb( Index: integer ): String;
Begin
     Case Index Of
          0: Result := 'Aducom Software ...';
     End;
End;

Procedure TRaSQLiteEditor.ExecuteVerb( Index: integer );
Begin
     Case Index Of
          0: ;
     End;
End;

function TDatabasePropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paMultiSelect, paDialog, paValueList, paRevertable];
end;

procedure TDatabasePropertyEditor.GetValues(Proc: TGetStrProc);
var
  sr: TSearchRec;
begin
  with GetComponent(0) as TRaSQLiteDB do begin
    if DefaultExt = '' then DefaultExt := '.db';
    if DefaultExt[1]<> '.' then DefaultExt := '.'+DefaultExt;
    if DefaultDir <> '' then
       if DefaultDir[Length(DefaultDir)]<>'\' then
          DefaultDir := DefaultDir + '\';
    if FindFirst(DefaultDir+'*'+DefaultExt,faAnyFile, sr) = 0 then begin
       repeat
         Proc(sr.Name);
       until FindNext(sr) <> 0;
       FindClose(sr);
    end;
  end;
  Proc(':memory:');
end;

function TDatabasePropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TDatabasePropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TTablePropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paMultiSelect, paDialog, paValueList, paRevertable];
end;

procedure TTablePropertyEditor.GetValues(Proc: TGetStrProc);
var MyList : TStringList;
    i      : integer;
begin
 with GetComponent(0) as TRaSQLiteTable do begin
  if Connection = nil then begin
    raise RaSqliteError.Create('no database connection');
    exit;
  end;
  MyList := TStringList.Create;
  Connection.GetTableNames(MyList, true);
  if MyList.Count > 0 then
     for i := 0 to MyList.Count - 1 do Proc(MyList[i]);
  MyList.Free;
 end;
end;

function TTablePropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TTablePropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TMasterDetailPropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paRevertable];
end;

procedure TMasterDetailPropertyEditor.GetValues(Proc: TGetStrProc);
var
    i,p    : integer;
    r      : string;
    oldr   : string;
begin
 with GetComponent(0) as TRaSQLiteBaseQuery do begin
   if not Assigned(MasterSource) then begin
      Proc('');
      exit;
   end;
   if not Assigned(MasterSource.Dataset) then begin
      Proc('');
      exit;
   end;

   FormMasterDetail := TFormMasterDetail.Create(Application);

   if not Active then open;
   if not Active then exit;

   for i := 0 to FieldDefs.Count - 1 do
       FormMasterDetail.LBDetail.Items.Add(FieldDefs.Items[i].Name);

   if not Mastersource.Dataset.Active then Mastersource.DataSet.Open;
   if not Mastersource.Dataset.Active then exit;

   for i := 0 to MasterSource.DataSet.FieldDefs.Count - 1 do
       FormMasterDetail.LBMaster.Items.Add(MasterSource.DataSet.FieldDefs.Items[i].Name);

   r := MasterFields;
   Oldr := r;
   while r <> '' do begin
    p := pos(';', r);
    if p = 0 then begin
       if Trim(r) <> '' then FormMasterDetail.LBLinked.Items.Add(Trim(r));
       r := '';
    end else begin
       FormMasterDetail.LBLinked.Items.Add(Trim(Copy(r, 1, p-1)));
       System.Delete(r, 1, p);
    end;
   end;
   if FormMasterDetail.ShowModal = mrOk then begin
      for i := 0 to FormMasterDetail.LBLinked.Items.Count - 1 do begin
          r := r + FormMasterDetail.LBLinked.Items[i]+';';
      end;
   end else r := oldr;
   FormMasterDetail.Free;
 end;
 Proc(r);
end;

function TMasterDetailPropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TMasterDetailPropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TStoragePropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paRevertable];
end;

procedure TStoragePropertyEditor.GetValues(Proc: TGetStrProc);
begin
  Proc('DEFAULT');
  Proc('MEMORY');
  Proc('FILE');
end;

function TStoragePropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TStoragePropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TSyncPropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paRevertable];
end;

procedure TSyncPropertyEditor.GetValues(Proc: TGetStrProc);
begin
  Proc('FULL');
  Proc('NORMAL');
  Proc('OFF');
end;

function TSyncPropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TSyncPropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TDirPropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paRevertable];
end;

procedure TDirPropertyEditor.GetValues(Proc: TGetStrProc);
var Dir : string;
begin
  Dir := 'C:\';
  SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],0);
  Proc(Dir);
end;

function TDirPropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TDirPropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TDLLDirPropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paRevertable];
end;

procedure TDLLDirPropertyEditor.GetValues(Proc: TGetStrProc);
var Dir : string;
begin
  Dir := 'C:\';
  SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],0);
  if Dir[Length(Dir)]<>'\' then Dir := Dir +'\';
  Proc(Dir+'sqlite3.dll');
end;

function TDLLDirPropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TDLLDirPropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TFileTypePropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paRevertable];
end;

procedure TFileTypePropertyEditor.GetValues(Proc: TGetStrProc);
begin
  Proc('htmlfile');
  Proc('xmlfile');
  Proc('textfile');
end;

function TFileTypePropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TFileTypePropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TTransactionPropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paRevertable];
end;

procedure TTransactionPropertyEditor.GetValues(Proc: TGetStrProc);
begin
  Proc('DEFAULT');
  Proc('DEFERRED');
  Proc('IMMEDIATE');
  Proc('EXCLUSIVE');
end;

function TTransactionPropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TTransactionPropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

function TCharEncPropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paRevertable];
end;

procedure TCharEncPropertyEditor.GetValues(Proc: TGetStrProc);
begin
  Proc('STANDARD');
  Proc('UTF8');
end;

function TCharEncPropertyEditor.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TCharEncPropertyEditor.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

end.
